package com.ruoyi.resturant.service.impl;

import com.ruoyi.common.exception.BizException;
import com.ruoyi.resturant.domain.ResBanner;

import com.ruoyi.resturant.mapper.ResBannerMapper;

import com.ruoyi.resturant.service.IResBannerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResBannerServiceImpl implements IResBannerService {
    private static final Logger log = LoggerFactory.getLogger( ResBannerServiceImpl.class);
    @Autowired
    private ResBannerMapper resBannerMapper;

    /**
     * 查询轮播图
     *
     * @param id 轮播图主键
     * @return 轮播图
     */
    @Override
    public ResBanner selectResBannerById(Long id)
    {
        return resBannerMapper.selectResBannerById(id);
    }


    /**
     * 查询轮播图列表
     *
     * @param bannerName 商铺名称
     * @return 轮播图
     */
    @Override
    public List<ResBanner> selectResBannerByParam(String bannerName)
    {

        return resBannerMapper.selectResBannerByParam(bannerName);
    }


    /**
     * 新增轮播图
     *
     * @param resBanner 轮播图
     * @return 结果
     */
    @Override
    public int insertResBanner(ResBanner resBanner)
    {
        // TODO 0：插入成功
        return resBannerMapper.insertResBanner(resBanner);
    }

    /**
     * 修改轮播图
     *
     * @param resBanner 轮播图
     * @return 结果
     */
    @Override
    public int updateResBanner(ResBanner resBanner)
    {

        // TODO 0：更新成功
        return resBannerMapper.updateResBanner(resBanner);
    }


    /**
     * 删除轮播图信息
     *
     * @param id 轮播图主键
     * @return 结果
     */
    @Override
    public int deleteResBannerById(Long id)
    {
        ResBanner resBanner =resBannerMapper.selectResBannerById(id);
//        如果学生不存在的话抛出异常
        if (resBanner == null){
            throw new BizException(404,"该轮播图ID"+id+"不存在");
        }
        log.info("该轮播图id"+id+"存在");
        // TODO 0：删除成功
        return resBannerMapper.deleteResBannerById(id);
    }
    }
